#define _CRT_SECURE_NO_WARNINGS 1

  struct ListNode {
 	int val;
 	struct ListNode *next;
 	ListNode(int x) : val(x), next(nullptr) {}
  };
 
class Solution {
public:
    ListNode* oddEvenList(ListNode* head)
    {
        if (head == nullptr) return nullptr;
        ListNode* odd = head;
        if (odd->next == nullptr) return head;
        ListNode* even = head->next;
        ListNode* even_head = even;
        while (even && even->next)
        {
            // ListNode* cur=head;
            // while(cur)
            // {
            //     cerr<<cur->val<<"->";
            //     cur=cur->next;
            // }
            // cerr<<endl;
            odd->next = even->next;
            even->next = even->next->next;
            odd->next->next = even_head;
            odd = odd->next;
            even = even->next;
            //cerr<<"end"<<endl;
        }
        return head;
    }
};